import { request } from '@/utils/request'
import type { User } from '@/types/user'

export const login = (data: { adminname: string; password: string }) => {
  return request<{ token: string }>({
    url: 'admin/login',
    method: 'POST',
    data
  })
}

// 获取用户信息
export const getUserInfo = () => {
  return request<User>({
    url: 'admin/detail'
  })
}

// 分页获取用户信息
export const getUserList = (data: {
  page: number
  pageSize: number
  nickname: string
}) => {
  return request<{ total: number; items: User[] }>({
    url: 'admin/list',
    data
  })
}

// 新增用户
export const addUser = (data: Partial<User>) => {
  return request({
    url: 'admin/add',
    method: 'POST',
    data
  })
}

// 修改用户
export const updateUser = (data: Partial<User>) => {
  return request({
    url: 'admin/update',
    method: 'POST',
    data
  })
}

// 删除用户
export const delUser = (data: { adminid: string }) => {
  return request({
    url: 'admin/delete',
    method: 'POST',
    data
  })
}
